package cn.iocoder.yudao.module.train.dal.mysql.classsetting;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.train.dal.dataobject.classsetting.ClassSettingDO;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.ClassSettingDTO;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.CourseClassesCommodityDTO;
import cn.iocoder.yudao.module.train.dal.dataobject.courseclasses.CourseClassesDO;
import cn.iocoder.yudao.module.train.dal.dataobject.coursecommodity.CourseCommodityDO;
import cn.iocoder.yudao.module.train.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.train.dal.dataobject.venue.VenueDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.train.controller.admin.classsetting.vo.*;

/**
 * 排课 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ClassSettingMapper extends BaseMapperX<ClassSettingDO> {

    default List<ClassSettingDO> selectList(ClassSettingPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ClassSettingDO>()
                .eqIfPresent(ClassSettingDO::getClassesId, reqVO.getClassesId())
                .eqIfPresent(ClassSettingDO::getSequence, reqVO.getSequence())
                .eqIfPresent(ClassSettingDO::getWeekly, reqVO.getWeekly())
                .eqIfPresent(ClassSettingDO::getWeekNumber, reqVO.getWeekNumber())
                .eqIfPresent(ClassSettingDO::getYearNumber,reqVO.getYearNumber())
                .eqIfPresent(ClassSettingDO::getVenueId, reqVO.getVenueId())
                .betweenIfPresent(ClassSettingDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ClassSettingDO::getId));
    }


    default List<ClassSettingDTO> selectListDetail(ClassSettingPageReqVO reqVO) {
        MPJLambdaWrapper<ClassSettingDO> wrapper = new MPJLambdaWrapper<ClassSettingDO>()
                .selectAll(ClassSettingDO.class)
                .select(CourseClassesDO::getClassNumber)
                .leftJoin(CourseClassesDO.class,CourseClassesDO::getId,ClassSettingDO::getClassesId)
                .select(CourseCommodityDO::getCommodityName)
                .leftJoin(CourseClassesDO.class,CourseClassesDO::getId,ClassSettingDO::getClassesId)
                .leftJoin(CourseCommodityDO.class,CourseCommodityDO::getId,CourseClassesDO::getCommodityId)
                .select(VenueDO::getVenueNo)
                .leftJoin(VenueDO.class,VenueDO::getId,ClassSettingDO::getVenueId)
                .eqIfExists(ClassSettingDO::getClassesId, reqVO.getClassesId())
                .eqIfExists(ClassSettingDO::getSequence, reqVO.getSequence())
                .eqIfExists(ClassSettingDO::getWeekly, reqVO.getWeekly())
                .eqIfExists(ClassSettingDO::getWeekNumber, reqVO.getWeekNumber())
                .eqIfExists(ClassSettingDO::getYearNumber,reqVO.getYearNumber())
                .eqIfExists(ClassSettingDO::getVenueId, reqVO.getVenueId())
                .orderByDesc(ClassSettingDO::getId);
        if (reqVO.getCreateTime() != null && reqVO.getCreateTime().length == 2) {
            wrapper.between(ClassSettingDO::getCreateTime, reqVO.getCreateTime()[0], reqVO.getCreateTime()[1]);
        }
        return selectJoinList(ClassSettingDTO.class, wrapper);
    }
}
